<?php
/**
 * Created by PhpStorm.
 * User: 70791
 * Date: 2020/7/28
 * Time: 14:07
 */

namespace App\HttpController\Api;

use EasySwoole\Component\Di;
use priestll\easyswoole\http\Auth;

class Award extends Auth
{
    protected $NO_AUTH_LIST = ['getLuckyRanking'];
    /**
     * @Di(key="AWARDS_BIZ")
     */
    protected $biz;

    /**
     * @Api(name="getAward",group="/api/award",description="当前活动奖品信息",path="/api/award/getAward")
     * @ApiAuth(name="authorization",type=string,from={'HEADER'},description="token")
     * @Method(allow={GET})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     */
    public function getAward()
    {
        $user = $this->getUser();
        $res = $this->biz->getAward($user);
        if ($res['status']) {
            return $this->success($res['data']);
        } else {
            return $this->fail($res['data']);
        }
    }


    /**
     * @Api(name="getRanking",group="/api/award",description="获取最新中奖信息",path="/api/award/getAward")")
     * @Method(allow={GET})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     */
    public function getLuckyRanking()
    {
        $user = $this->getUser();
        $res = $this->biz->ranking($user);
        if ($res['status']) {
            return $this->success($res['data']);
        } else {
            return $this->fail($res['data']);
        }
    }


    /**
     * @Api(name="getLuckyLog",group="/api/award",description="获取中奖记录",path="/api/award/getLuckyLog")")
     * @Method(allow={GET})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     * @Param(name="page",alias="当前页数",integer="")
     */
    public function getLuckyLog()
    {
        $user = $this->getUser();
        $param = $this->request()->getRequestParam();
        $res = $this->biz->log($user,$param["page"]);
        if ($res['status']) {
            return $this->success($res['data']);
        } else {
            return $this->fail($res['data']);
        }
    }


    /**
     * @Api(name="getDetails",group="/api/award",description="获取二维码",path="/api/award/getDetails")
     * @ApiAuth(name="authorization",type=string,from={'HEADER'},description="token")
     * @Method(allow={GET})
     * @ResponseParam(name="code",description="状态码")
     * @ResponseParam(name="result",description="api请求结果")
     * @ResponseParam(name="msg",description="api提示信息")
     * @ApiSuccess({"code":200,"result":[],"msg":"SUCCESS"})
     * @ApiFail({"code":400,"result":[],"msg":"FAIL"})
     * @Param(name="id",alias="记录id",integer="")
     */
    public function getDetails()
    {
        $user = $this->getUser();
        $param = $this->request()->getRequestParam();
        $res = $this->biz->details($param["id"],$user["id"]);
        if ($res['status']) {
            return $this->success($res['data']);
        } else {
            return $this->fail($res['data']);
        }
    }
}